package com.txts.road.admin.vehicleSys.controller;

import com.github.pagehelper.PageInfo;
import com.txts.base.common.domain.PageResult;
import com.txts.base.common.domain.ResponseDTO;
import com.txts.road.admin.common.annotation.Anonymous;
import com.txts.road.admin.common.annotation.Log;
import com.txts.road.admin.common.core.controller.BaseController;
import com.txts.road.admin.common.core.domain.AjaxResult;
import com.txts.road.admin.common.core.page.TableDataInfo;
import com.txts.road.admin.common.enums.BusinessType;
import com.txts.road.admin.common.utils.poi.ExcelUtil;
import com.txts.road.admin.vehicleSys.domain.liveVehicle;
import com.txts.road.admin.vehicleSys.service.IliveVehicleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * 生活车辆Controller
 *
 * @author ruoyi
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/vehicleSys/liveVehicle")
@Tag(name = "生活车辆接口")
public class liveVehicleController extends BaseController {
    @Resource
    private IliveVehicleService liveVehicleService;

    /**
     * 查询生活车辆列表
     */
    @Anonymous
    @GetMapping("/list")
    @Operation(summary = "查询生活车辆列表", description = "根据条件查询生活车辆列表")
    public ResponseDTO<PageResult<liveVehicle>> list(liveVehicle liveVehicle) {
        startPage();
        List<liveVehicle> list = liveVehicleService.selectliveVehicleList(liveVehicle);
        return getDataTable(list);
    }

    /**
     * 导出生活车辆列表
     */
    @PreAuthorize("@ss.hasPermi('vehicleSys:liveVehicle:export')")
    @Log(title = "生活车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出生活车辆列表", description = "导出生活车辆列表")
    public void export(HttpServletResponse response, liveVehicle liveVehicle) {
        List<liveVehicle> list = liveVehicleService.selectliveVehicleList(liveVehicle);
        ExcelUtil<liveVehicle> util = new ExcelUtil<liveVehicle>(liveVehicle.class);
        util.exportExcel(response, list, "生活车辆数据");
    }

    /**
     * 获取生活车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('vehicleSys:liveVehicle:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取生活车辆详细信息", description = "根据ID获取生活车辆详细信息")
    public ResponseDTO<Object> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(liveVehicleService.selectliveVehicleById(id));
    }

    /**
     * 新增生活车辆
     */
    @PreAuthorize("@ss.hasPermi('vehicleSys:liveVehicle:add')")
    @Log(title = "生活车辆", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增生活车辆", description = "新增生活车辆")
    public ResponseDTO<Object>add(@RequestBody liveVehicle liveVehicle) {
        return toAjax(liveVehicleService.insertliveVehicle(liveVehicle));
    }

    /**
     * 修改生活车辆
     */
    @PreAuthorize("@ss.hasPermi('vehicleSys:liveVehicle:edit')")
    @Log(title = "生活车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改生活车辆", description = "修改生活车辆")
    public ResponseDTO<Object>edit(@RequestBody liveVehicle liveVehicle) {
        return toAjax(liveVehicleService.updateliveVehicle(liveVehicle));
    }

    /**
     * 删除生活车辆
     */
    @PreAuthorize("@ss.hasPermi('vehicleSys:liveVehicle:remove')")
    @Log(title = "生活车辆", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除生活车辆", description = "删除生活车辆")
    public ResponseDTO<Object>remove(@PathVariable Long[] ids) {
        return toAjax(liveVehicleService.deleteliveVehicleByIds(ids));
    }


    @GetMapping("/listAllcheshou")
    @Operation(summary = "查询所有车手", description = "查询所有车手列表")
     public ResponseDTO<Object> listAllcheshou() {
        return AjaxResult.success(liveVehicleService.selectAllcheshou());
    }
}
